<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>todeList</title>
    <style>
        .v-enter-from,.v-leave-to {
            opacity: 0;
            transform: translateY(50px);
        }
        .v-enter-active,.v-leave-active {
            transition: all 0.5s;
        }
        .v-enter-to,.v-leave-from {
            opacity: 1;
            transform: translateY(0);
        }
        .li-item {
            display: inline-block;
            margin-right: 20px;
        }
    </style>
</head>
<body>
    <div id="root"></div>
    <script src="./vue3基础源码/vue3.js"></script>
    <script>
        const app = Vue.createApp({
            data(){
                return {
                    list:[],
                    inputValue:''
                }
            },
            methods:{
                addClick(){
                    this.list.push(this.inputValue
                    );
                    this.inputValue = '';
                },
                delClick(index){
                    this.list.splice(index,1);
                }
            },
            template:`
                <div>
                    <input v-model="inputValue"/>
                    <button v-on:click="addClick">增加</button>
                    <ul>
                        <todo-item class="li-item" v-for="(item,index) of list" v-bind:content="item" v-bind:index="index" @del-dom="delClick"/>
                    </ul>
                </div>            
            `
        })

        app.component("todo-item",{
            props:['index','content'],
            methods:{
                one(){
                    this.$emit('delDom',this.index);
                }
            },
            template:`<li @click="one">{{index}}------{{content}}</li>`
        })
        app.mount("#root");
    </script>
</body>
</html>